// pages/share70/index.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    visible: false,
    display:'block',
    img: [
      app.globalData.serverUrl +"uploads/wxxcx/1.jpg",
      app.globalData.serverUrl +"uploads/wxxcx/2.jpg",
      app.globalData.serverUrl +"uploads/wxxcx/3.jpg",
      app.globalData.serverUrl +"uploads/wxxcx/4.jpg",
      app.globalData.serverUrl +"uploads/wxxcx/5.jpg",
      app.globalData.serverUrl +"uploads/wxxcx/6.jpg",
      app.globalData.serverUrl +"uploads/wxxcx/7.jpg",
      app.globalData.serverUrl +"uploads/wxxcx/8.jpg",
      app.globalData.serverUrl + "uploads/wxxcx/9.jpg"
    ],
    picHeight: '180px',
    picWidth: '110px',
    topNavH: '65px',
    paddingLeft: '6px',
    pageHeght: '100%'
  },
 
  previewImage:function(e){ 
    var that = this 
    
    var current = e.target.dataset.src;
      wx.previewImage({
        current: current,
        urls: that.data.img,
        success: function(){
            
            // wx.showToast({
            //   title: '长按分享图片',
            //   icon: 'none',
            //   duration: 3000,

            //   success: function () {

            //     // setTimeout(function () {

            //     // }, 62000)

            //   }
            // })          
        },
        complete: function(){
          // wx.showToast({
          //   title: '长按分享图片',
          //   icon: 'none',
          //   duration: 3000,

          //   success: function () {

          //     // setTimeout(function () {

          //     // }, 62000)

          //   }
          // })  
        }
      })
    
    
     
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.getSystemInfo({
      success: function (res) {
        console.log('sharewidth' + res.windowWidth)
        console.log('shareHeight' + res.windowHeight)
        console.log('window.devicePixelRatio=>' + res.pixelRatio)
        var windowHeight = res.windowHeight;
        var windowWidth = res.windowWidth;
        var statusBarHeight = res.statusBarHeight;
        that.setData({
          picHeight: (windowHeight/640*240)+'px',
          picWidth: (windowWidth/360*160) + 'px',
          picHeight: (windowHeight / 640 * 240) + 'px',
          picWidth: (windowWidth / 360 * 160) + 'px',
          topNavH: (statusBarHeight + 45) + 'px',
          paddingLeft: (windowWidth/360*8) + 'px',
          pageHeght: (windowHeight-55) + 'px'
        })
      }
    })
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {    
    var that = this
    that.setData({
      display: 'block'
    })
    setTimeout(function () {
      that.setData({
        display: 'none'
      })
      
    }, 5000)
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let users = wx.getStorageSync('userInfo');
    // if (res.from === 'button') { }
    return {
      title: '青岛市特种设备安全智慧体验中心',
      path: '/pages/scancode/index',
      success: function (res) {
        wx.showToast({
          title: '已转发',
          icon: 'success',
          duration: 2000
        })
      }
    }
   
  }
})